package day05;
import  java.util.Arrays;
//数组的演示
public class ArrayDemo {
    public static void main(String[] args) {

        //声明一个整型数组arr,数组中有10个元素，每个元素默认值为0
        int[] arr=new int[10];
        for (int i=0;i<arr.length;i++){
            arr[i]=(int)(Math.random()*100);
            System.out.println(arr[i]);
        }
        Arrays.sort(arr);
        System.out.println("排序后输出：");

        for (int i=0;i<arr.length;i++){
            System.out.println(arr[i]);
        }

        System.out.println("倒着输出：");
        for(int i=arr.length-1;i>=0;i--){//数据还是升序的，
            System.out.println(arr[i]);
        }

        System.out.println("第一个元素："+arr[0]);



/*
        int[] arr=new int[10];
        for (int i=0;i<arr.length;i++){
            arr[i]=(int)(Math.random()*100);//[0,99]
            System.out.println(arr[i]);
        }

 */













/*
        int[] a=new int[5];//默认值为0
        double[] d=new double[10];//

        boolean[] b=new boolean[26];
        for (boolean d1:b){
            System.out.println(d1);
        }

        int[] a1=new int[10];
        double[] d1=new double[13];
        boolean[] b1=new boolean[18];

        int[] arr1=new int[3];
        int[] arr2={1,4,6};
        int[] arr3=new int[]{2,5,8};
        int[] arr4;
//        arr4={2,4,6};//编译错误，此种方式只能声明同时初始化
        arr4=new int[]{2,5,76};

        int[] arr0={1,4,5};
         int[] arr5=new int[]{1,4,5};
        int[] arr6;
        arr6=new int[]{1,4,6};

        int[] a0=new int[7];
        a0=new int[]{1,2,3,4,5,6,7};
        int[] arr7={4,6,7,8,9};
        int[] arr8=new int[100];
        arr8[0]=3;

        int[] arr=new int[3];
        System.out.println("数组长度："+arr.length);
        System.out.println(arr[0]);//0
        arr[0]=100;
        arr[1]=200;
        arr[2]=300;
        System.out.println(arr[arr.length-1]);//300

        int[] arr9=new int[3];
        System.out.println(arr9.length);
        System.out.println(arr9[2]);
        arr9[0]=23;
        arr9[1]=78;
        arr9[2]=90;
//        arr9[3]=100;//运行时会发生数组下标越界的异常
        System.out.println(arr9[arr9.length-1]);

 */




    }
}
